package app

import (
	// "fmt"
	// "time"

	"github.com/go-apibox/api"
	"github.com/go-apibox/filter"
)

func ActionTaskLogList(c *api.Context) interface{} {
	params := c.NewParams()
	params.AddPagination().AddOrderBy("CreateTime", "desc", []string{"CreateTime"}, false)
	params.Add("DeviceGroupId", filter.EmptyToNil(), filter.Uint32())
	params.Add("ProductId", filter.EmptyToNil(), filter.Uint32())
	params.Add("TaskId", filter.EmptyToNil(), filter.Uint32())
	params.Add("DeviceGroupName", filter.EmptyToNil(), filter.String())
	params.Add("Account", filter.EmptyToNil(), filter.String())
	params.Add("ProductCode", filter.EmptyToNil(), filter.String())
	params.Add("ProductTitle", filter.EmptyToNil(), filter.String())
	if apiErr := params.Parse(); apiErr != nil {
		return apiErr
	}

	list := make([]*TaskLog, 0, 10)
	return api.List(c, &list, params, nil)
	// return api.ListJoin(c, &list, params, map[string]string{
	// 	"DeviceGroupName": "table:device_group",
	// 	"Account":         "like",
	// 	"ProductCode":     "like",
	// 	"ProductTitle":    "like",
	// },
	// 	[][]string{
	// 		[]string{"INNER", "device_group", "device_group.device_group_id=task_product.device_group_id"},
	// 	},
	// )
}

func ActionTaskLogDetail(c *api.Context) interface{} {
	params := c.NewParams()
	params.Add("TaskLogId", filter.EmptyToNil(), filter.Required(), filter.Uint64())
	if apiErr := params.Parse(); apiErr != nil {
		return apiErr
	}
	return api.Detail(c, new(TaskLog), params)
}

func ActionTaskLogDelete(c *api.Context) interface{} {
	params := c.NewParams()
	params.Add("TaskLogId", filter.EmptyToNil(), filter.Required(), filter.Uint64())
	if apiErr := params.Parse(); apiErr != nil {
		return apiErr
	}
	return api.Delete(c, new(TaskLog), params)
}
